/*    */ package com.cr.common.utils.file;
/*    */ 
/*    */ import com.cr.common.config.RuoYiConfig;
/*    */ import com.cr.common.utils.MyStringUtils;
/*    */ import java.io.ByteArrayInputStream;
/*    */ import java.io.ByteArrayOutputStream;
/*    */ import java.io.FileInputStream;
/*    */ import java.io.InputStream;
/*    */ import java.net.URL;
/*    */ import java.net.URLConnection;
/*    */ import java.util.Arrays;
/*    */ import org.apache.poi.util.IOUtils;
/*    */ import org.slf4j.Logger;
/*    */ import org.slf4j.LoggerFactory;
/*    */ 
/*    */ public class ImageUtils {
/* 24 */   private static final Logger log = LoggerFactory.getLogger(ImageUtils.class);
/*    */   
/*    */   public static byte[] getImage(String imagePath) {
/* 28 */     InputStream is = getFile(imagePath);
/*    */     try {
/* 31 */       return IOUtils.toByteArray(is);
/* 33 */     } catch (Exception e) {
/* 35 */       log.error("图片加载异常 {}", e);
/* 36 */       return null;
/*    */     } finally {
/* 40 */       IOUtils.closeQuietly(is);
/*    */     } 
/*    */   }
/*    */   
/*    */   public static InputStream getFile(String imagePath) {
/*    */     try {
/* 48 */       byte[] result = readFile(imagePath);
/* 49 */       result = Arrays.copyOf(result, result.length);
/* 50 */       return new ByteArrayInputStream(result);
/* 52 */     } catch (Exception e) {
/* 54 */       log.error("获取图片异常 {}", e);
/* 56 */       return null;
/*    */     } 
/*    */   }
/*    */   
/*    */   public static byte[] readFile(String url) {
/* 67 */     InputStream in = null;
/* 68 */     ByteArrayOutputStream baos = null;
/*    */     try {
/* 71 */       if (url.startsWith("http")) {
/* 74 */         URL urlObj = new URL(url);
/* 75 */         URLConnection urlConnection = urlObj.openConnection();
/* 76 */         urlConnection.setConnectTimeout(30000);
/* 77 */         urlConnection.setReadTimeout(60000);
/* 78 */         urlConnection.setDoInput(true);
/* 79 */         in = urlConnection.getInputStream();
/*    */       } else {
/* 84 */         String localPath = RuoYiConfig.getProfile();
/* 85 */         String downloadPath = localPath + MyStringUtils.substringAfter(url, "/profile");
/* 86 */         in = new FileInputStream(downloadPath);
/*    */       } 
/* 88 */       return IOUtils.toByteArray(in);
/* 90 */     } catch (Exception e) {
/* 92 */       log.error("获取文件路径异常 {}", e);
/* 93 */       return null;
/*    */     } finally {
/* 97 */       IOUtils.closeQuietly(in);
/* 98 */       IOUtils.closeQuietly(baos);
/*    */     } 
/*    */   }
/*    */ }


/* Location:              D:\tmp\creditorRights-admin\BOOT-INF\lib\creditorRights-common-4.7.0.jar!\com\cr\commo\\utils\file\ImageUtils.class
 * Java compiler version: 8 (52.0)
 * JD-Core Version:       1.1.3
 */